home *** CD-ROM | disk | FTP | other *** search
- //============================================================================
- // control/server/weapons/weapon.cs
- // Copyright (c) 2003, 2006 Kenneth C. Finney2003, 2006 by Kenneth
- // Portions Copyright (c) 2001 GarageGames.com
- // Portions Copyright (c) 2001 by Sierra Online, Inc.
- //============================================================================
- $WeaponSlot = 0;
- function Weapon::OnUse(%data,%obj)
- {
- if (%obj.GetMountedImage($WeaponSlot) != %data.image.GetId())
- {
- %obj.mountImage(%data.image, $WeaponSlot);
- if (%obj.client)
- MessageClient(%obj.client, 'MsgWeaponUsed', '\c0Weapon selected');
- }
- }
- function Weapon::OnPickup(%this, %obj, %shape, %amount)
- {
- if (Parent::OnPickup(%this, %obj, %shape, %amount))
- {
- if ( (%shape.GetClassName() $= "Player" ||
- %shape.GetClassName() $= "AIPlayer" ) &&
- %shape.GetMountedImage($WeaponSlot) == 0)
- {
- %shape.Use(%this);
- }
- }
- }
- function Weapon::OnInventory(%this,%obj,%amount)
- {
- if (!%amount && (%slot = %obj.GetMountSlot(%this.image)) != -1)
- %obj.UnmountImage(%slot);
- }
- function WeaponImage::OnMount(%this,%obj,%slot)
- {
- if (%obj.GetInventory(%this.ammo))
- %obj.SetImageAmmo(%slot,true);
- }
- function Ammo::OnPickup(%this, %obj, %shape, %amount)
- {
- if (Parent::OnPickup(%this, %obj, %shape, %amount))
- {
-
- }
- }
- function Ammo::OnInventory(%this,%obj,%amount)
- {
- for (%i = 0; %i < 8; %i++)
- {
- if ((%image = %obj.GetMountedImage(%i)) > 0)
- if (IsObject(%image.ammo) && %image.ammo.GetId() == %this.GetId())
- %obj.SetImageAmmo(%i,%amount != 0);
- }
- }
- function RadiusDamage(%sourceObject, %position, %radius, %damage, %damageType, %impulse)
- {
- InitContainerRadiusSearch(%position, %radius, $TypeMasks::ShapeBaseObjectType);
-
- %halfRadius = %radius / 2;
- while ((%targetObject = ContainerSearchNext()) != 0) {
- %coverage = CalcExplosionCoverage(%position, %targetObject,
- $TypeMasks::InteriorObjectType | $TypeMasks::TerrainObjectType |
- $TypeMasks::ForceFieldObjectType | $TypeMasks::VehicleObjectType);
- if (%coverage == 0)
- continue;
- %dist = ContainerSearchCurrRadiusDist();
- %distScale = (%dist < %halfRadius)? 1.0:
- 1.0 - ((%dist - %halfRadius) / %halfRadius);
- %targetObject.Damage(%sourceObject, %position,
- %damage * %coverage * %distScale, %damageType);
- if (%impulse) {
- %impulseVec = VectorSub(%targetObject.GetWorldBoxCenter(), %position);
- %impulseVec = VectorNormalize(%impulseVec);
- %impulseVec = VectorScale(%impulseVec, %impulse * %distScale);
- %targetObject.ApplyImpulse(%position, %impulseVec);
- }
- }
- }
-